# -*- coding: utf-8 -*-
# @Author : zhaochen
# @Date   : 2019/7/10
# @File   : IC_UdestroyNoTiCompCardAcctCnt.py
# @E-mail : zhaochen@bbdservice.com

'''eof
name:个人当前未销户非小额度贷记卡账户数
code:IC_UdestroyNoTiCompCardAcctCnt
tableName:
columnName:
groups:个人征信模块
dependencies:IC_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']

def getTable(table_Name):
    try:
        data = IC_DSJ['data'].get(table_Name)
        if data in null_type_list:
            return None
        else:
            # 存在1条为空的数据[{}]
            if isinstance(data, list) and len(data) == 1 and data[0]['reportNo'] in null_type_list:
                return [{}]
            # 存在表 但为空list []
            elif isinstance(data, list) and len(data) == 0:
                return None
            else:
                return data
    except:
        return None

def isfloat(x):
    '''
    判断x为float类型且大于等于0
    :param x:
    :return:
    '''
    try:
        if isinstance(float(x), float) and float(x)>=0:
            if str(x) in ['inf', 'infinity', 'INF', 'INFINITY', 'True']:
                return False
            else:
                return True
        else:
            return False
    except:
        return False

def IC_UdestroyNoTiCompCardAcctCnt():
    try:
        ICRLoancardInfo = getTable('ICRLoancardInfo002*Card')

        if ICRLoancardInfo in null_type_list:
            return u'缺失值'
        elif ICRLoancardInfo == [{}] :
            return 0
        else:
            list=[]
            for i in ICRLoancardInfo:

                CreditLimitAmount = i.get('CreditLimitAmount')
                State = i.get('state')
                if CreditLimitAmount  in null_type_list or State in null_type_list  :
                    list.append(0)
                elif float(CreditLimitAmount)>=1000 and State in ['正常','逾期'] :
                    list.append(1)
                else:
                    list.append(None)

        factor = [x for x in list if x is not None]
        if len(factor) == 0:
            return u'缺失值'
        else:
            return sum(factor)
    except:
        return u'缺失值'

result = IC_UdestroyNoTiCompCardAcctCnt()